package com.fuyun.rpc.config;

import cn.hutool.core.util.StrUtil;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author fuyun。
 * @Date 2025/8/21 16:36。
 * @Description: TODO。
 **/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class RpcServiceConfig {
    private String version;
    private String group;
    private Object service;

    public  RpcServiceConfig(Object service) {
        this.service = service;
    }

    public List<String> rpcServerNames() {
        return interfaceNames().stream()
                .map(interfaceNames -> interfaceNames + StrUtil.blankToDefault(getVersion(), StrUtil.EMPTY) + StrUtil.blankToDefault(getGroup(), StrUtil.EMPTY))
                .collect(Collectors.toList());
    }

    private List<String> interfaceNames() {
        return Arrays.stream(service.getClass().getInterfaces())
                .map(Class::getCanonicalName)
                .collect(Collectors.toList());
    }

}
